const express = require('express');
const db = require('./config/db');
const h5Routes = require('./api/h5/routes/h5Routes');
const adminRoutes = require('./api/admin/routes/adminRoutes');
const app = express();

// 测试数据库连接
db.query('SELECT 1')
    .then(() => console.log('MySQL connected'))
    .catch((err) => console.error('MySQL connection error:', err));

// 加载中间件
app.use(express.json());

// 加载静态资源
app.use('/uploads', express.static('public/uploads'));

// 加载路由
app.use('/api', h5Routes);
app.use('/admin', adminRoutes);
module.exports = app;